from django.db import models


# Create your models here.
class UserType(models.Model):
    name = models.CharField(max_length=20, unique=True)
    add_time = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'usertype'
        verbose_name = '用户类型表'
        verbose_name_plural = verbose_name


class User(models.Model):
    username = models.CharField(max_length=20, unique=True, verbose_name='用户名')
    password = models.CharField(max_length=20, verbose_name='密码')
    phone = models.CharField(max_length=11, verbose_name='手机号')
    add_time = models.DateTimeField(auto_now=True)
    # 声明外键关系名为users
    usertype = models.ForeignKey(to=UserType, on_delete=models.CASCADE,related_name='users', null=True)

    class Meta:
        db_table = 'user'
        verbose_name = '用户表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username
